package com.cskaoyan.controller;

import com.cskaoyan.bean.bo.AdComment;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.MarketGoods_list;
import com.cskaoyan.bean.common.Market_Goods_Comment;
import com.cskaoyan.bean.marketBean.MarketComment;
import com.cskaoyan.bean.vo.ZYL_admin_comment_deleteVO;
import com.cskaoyan.service.MarketGoods_zyl_Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("admin/comment")
public class ZylCommoditymanagementController_admin_comment {
    @Autowired
    MarketGoods_zyl_Service marketGoodsZylService;

    /**
     * 商品回显
     *
     * @param map
     * @return {@link MarketGoods_list}
     */

    @RequestMapping("list")
    public Market_Goods_Comment list(AdComment map) {
        PageHelper.startPage(map.getPage(), map.getLimit());
        List<MarketComment> comment = marketGoodsZylService.zyl_list_comment(map);
        PageInfo<MarketComment> pageInfo = new PageInfo<>(comment);
        Integer total = Math.toIntExact(pageInfo.getTotal());
        int pages;
        if (total % map.getLimit() > 0) {
            pages = (int) (total / map.getLimit() + 1);
        } else {
            pages = (int) (total / map.getLimit());
        }
        List<Market_Goods_Comment.DataDTO.ListDTO> listDTO = new ArrayList<>();
        for (MarketComment c : comment) {

           /* String gallery = c.getPicUrls();
            String str2 = "[";
            String str3 = "]";
            String str4 = "\"";
            String s = trimStr(gallery, str2);
            String s1 = trimStr(s, str3);
            String s2 = trimStr(s1, str4);
            String substring = s2.replace("\"", "");
            System.out.println("s3 = " + substring);


            String[] strings = substring.split(",",substring.length()-2);
            List<String> gallerys = new ArrayList();
            for (int i = 0; i < strings.length; i++) {
                gallerys.add(strings[i]);
            }
*/
            Market_Goods_Comment.DataDTO.ListDTO listDTO1 = new Market_Goods_Comment.DataDTO.ListDTO(c.getId(), c.getValueId(), c.getType().intValue(), c.getContent(), c.getAdminContent(), c.getUserId(), c.getHasPicture(), c.getPicUrls(), c.getStar().intValue(), c.getAddTime(), c.getUpdateTime(), c.getDeleted());
            listDTO.add(listDTO1);
        }

        Market_Goods_Comment.DataDTO dataDTO = new Market_Goods_Comment.DataDTO(total, pages, map.getLimit(), map.getPage(), listDTO);
        Market_Goods_Comment market_Goods_Comment = new Market_Goods_Comment(0, dataDTO, "成功");
        return market_Goods_Comment;
    }


    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody ZYL_admin_comment_deleteVO map) {
        System.out.println("map = " + map);
        BaseRespVo baseRespVo = new BaseRespVo();
        try {
            int i = marketGoodsZylService.deleteByPrimaryKey(map.getId());
            baseRespVo.setErrno(0);
            baseRespVo.setErrmsg("成功");
        } catch (Exception e) {
            baseRespVo.setErrno(404);
            baseRespVo.setErrmsg("失败");
        } finally {
            return baseRespVo;
        }
    }
}




